<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/8/14
 * Time: 15:05
 */

namespace App\Http\Controllers\Web;


use App\Service\PosterService;
use Illuminate\Http\Response;

class PosterController extends BaseController
{
    public function index()
    {
        $params = $this->request->post();
        return PosterService::getList($params,'order','ASC');
    }

    public function getPosterById()
    {
        $posterId = $this->request->post('id');
        if(!$posterId){
            return Response()->json(['code'=>200,'msg'=>'参数缺失']);
        }
        return PosterService::getPosterById($posterId);
    }

    public function add()
    {
        $params = $this->request->post();
        if(!isset($params['img_src']) || empty(trim($params['img_src']))){
            return Response()->json(['code'=>201,'msg'=>'请上传海报图片']);
        }
        $params['order'] = $this->request->post('order',0);
        return PosterService::add($params);
    }

    public function edit()
    {
        $params = $this->request->post();
        if(!isset($params['img_src']) || empty(trim($params['img_src']))){
            return Response()->json(['code'=>201,'msg'=>'请上传海报图片']);
        }
        
        $params['order'] = $this->request->post('order',0);
        return PosterService::edit($params);

    }

    public function destroy()
    {
        $ids = $this->request->post('ids');
        $ids = is_array($ids) ? $ids : [$ids];
        if(!$ids){
            return Response()->json(['code'=>201,'msg'=>'请选择要删除的海报图']);
        }
        return PosterService::destroy($ids);

    }

}
